<style rel="stylesheet/scss" lang="scss" scoped>
.mid {
  line-height: 140px;
}
button {
  margin: 3px;
}
</style>
<template>
  <div class="app-container calendar-list-container">
    <div class="pds-tip">
      <div class="title">认证申请</div>
    </div>
    <div>
      <el-button
        class="filter-item"
        type="success"
        icon="search"
        @click="$router.push({path:'plan/add'})"
        size="small"
      >认证申请</el-button>
      <div class="filter-container" style="float:right">
        <el-input
          style="width: 200px;"
          class="filter-item"
          placeholder="请输入项目编号或产品型号"
          v-model="pageData.params.key"
        ></el-input>
        <el-button class="filter-item" type="primary" icon="search" @click="search()">查询</el-button>
      </div>
    </div>
    <el-table
      :data="pageData.list"
      border
      fit
      highlight-current-row
      style="width: 100%"
      v-loading="loading"
    >
      <el-table-column width="50" align="center" label="序号">
        <template
          slot-scope="scope"
        >{{(pageData.params.page-1)*pageData.params.limit+(scope.$index+1)}}</template>
      </el-table-column>
      <el-table-column prop="projectNo" align="center" label="项目编号" min-width></el-table-column>
      <el-table-column prop="applyType" align="center" label="申请类型" min-width></el-table-column>
      <el-table-column prop="plmModelNo" align="center" label="产品型号" min-width></el-table-column>
      <el-table-column prop="productName" align="center" label="产品名称" min-width></el-table-column>
      <el-table-column prop="createTime" align="center" label="申请日期" min-width></el-table-column>
      <el-table-column prop="status" align="center" label="状态" min-width>
        <template slot-scope="scope">
          <span v-if="scope.row.status===0">草稿</span>
          <span v-if="scope.row.status===1">申请中</span>
          <span v-if="scope.row.status===2">已申请</span>
          <span v-if="scope.row.status===4">驳回</span>
        </template>
      </el-table-column>
      <el-table-column prop align="center" label="操作" min-width="100px">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="success"
            @click="$router.push({path:'plan/detail',query:{id:scope.row.id}})"
          >查看</el-button>
          <el-button
            size="small"
            type="primary"
            @click="$router.push({path:'plan/edit', query: {id: scope.row.id}})"
            v-if="scope.row.status===0||scope.row.status==4"
          >{{scope.row.status==2?'编辑':'编辑'}}</el-button>
          <el-button
            size="small"
            type="danger"
            v-if="scope.row.status===0"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :pageData="pageData.params" @pageChange="changePage" @changeSize="changeSize"></pagination>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import * as api from "@/api/cert/plan/index";
import * as prodApi from "@/api/product/index";
import ListRefresh from "@/components/Mixin/listRefresh.js";
export default {
  name: "user",
  components: {
    // 'depart-selector': () =>
    //   import ('./components/departSelector')
  },
  mixins: [ListRefresh],
  data() {
    return {
      loading: false,
      pageData: {
        params: {
          page: 1,
          limit: 10,
          total: 100
        },
        list: []
      }
    };
  },
  created() {
    this.getList();
  },
  computed: {
    ...mapGetters(["elements", "language"])
  },
  methods: {
    /* 列表页刷新 */
    refresh() {
      this.pageData.params.page = 1;
      this.getList();
    },
    handleDelete(row) {
      console.log(row);
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        type: "warning"
      })
        .then(() => {
          console.log(row.id);
          const params = { id: row.id };
          api.handleDelete(params).then(response => {
            console.log(response);
            if (response.code === 200) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    search() {
      this.pageData.params.page = 1;
      this.getList();
    },
    changePage(pageData) {
      this.pageData.params.page = pageData.page;
      this.getList();
    },
    changeSize(pageSize) {
      this.pageData.params.limit = pageSize;
      this.pageData.params.page = 1;
      this.getList();
    },
    getList() {
      const params = Object.assign({}, this.pageData.params);
      this.loading = true;
      api
        .getList(params)
        .then(response => {
          if (response.code === 200) {
            this.pageData.list = response.data.rows;
            this.pageData.params.total = response.data.total;
          }
          this.loading = false;
        })
        .catch(err => {
          this.loading = false;
          console.log(err);
        });
    }
  }
};
</script>
